package jd.monitor.attach.config;

import java.util.HashSet;
import java.util.List;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

@XStreamAlias("beans")
public class BeanRoot extends ConfigBase {
	
	@XStreamImplicit(itemFieldName="bean")
	private List<BeanConfig> beanList ;
	
	@XStreamAlias("classPath")
	private String classPath ;
	
	public List<BeanConfig> getBeanList() {
		return beanList;
	}

	public void setBeanList(List<BeanConfig> beanList) {
		this.beanList = beanList;
	}
	
	public String getClassPath() {
		return classPath;
	}

	public void setClassPath(String classPath) {
		this.classPath = classPath;
	}

	public HashSet<String> getBeanNames() {
		HashSet<String> beanNames = new HashSet<String>() ;
		for (BeanConfig beanConfig : beanList) {
			beanNames.add(beanConfig.name) ;
		}
		return beanNames;
	}
	
	public BeanConfig getBeanByName(String name) {
		for (BeanConfig beanConfig : beanList) {
			if(beanConfig.getName().equals(name))
				return beanConfig ;
		}
		return null;
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE);
	}
	
}
